package com.ejuornal.action;

import java.util.List;

import javax.annotation.Resource;

import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.ejuornal.bean.Ads;
import com.ejuornal.bean.Artical;
import com.ejuornal.bean.Category;
import com.ejuornal.bean.PerPeriodical;
import com.ejuornal.bean.vo.PermissionVO;
import com.ejuornal.service.AdsService;
import com.ejuornal.service.ArticalService;
import com.ejuornal.service.CategoryService;
import com.ejuornal.service.PerPeriodicalService;
import com.ejuornal.service.PermissionService;
import com.ejuornal.util.Constants;
import com.opensymphony.xwork2.ActionSupport;
/**
 * 项目名称：ejuornal    
 * 类名称：IndexAction    
 * 类描述：首页独立出来的表示层    
 * 创建人：陈晨    
 * 创建时间：Mar 5, 2013 11:41:39 AM    
 * 修改人：陈晨    
 * 修改时间：Mar 5, 2013 11:41:39 AM    
 * 修改备注：    
 * @version     
 */
@Component("indexAction")
@Scope("protetype")
public class IndexAction extends ActionSupport{
    private static final long serialVersionUID = -7464944869390870245L;
    private CategoryService cs;
    private PerPeriodicalService pps;
    private ArticalService as;
    private AdsService adsService;
    private List<PerPeriodical> perPeriodicals_0;
    private List<Category> categorys;
    private List<PerPeriodical> perPeriodicals_1;
    private List<Artical> articals;
    private Ads ads_center;
    private Ads ads_bottom;
    private int articaCount = 20;
    private int periodicalCount = 5;
    private int perPeriodicalCount = 10;
    private String url;
    private List<PermissionVO> pv;
    private PermissionService permissionService;
    
    public String index() {
        categorys = cs.findAll();
        perPeriodicals_0 = pps.findNew(perPeriodicalCount);
        perPeriodicals_1 = pps.findTop(periodicalCount);
        articals = as.findTop(articaCount);
        ads_center = adsService.findAdsByPosIdAndTime(1);
        ads_bottom = adsService.findAdsByPosIdAndTime(2);
        return SUCCESS;
    }
    
    public String apply_bw() {
        int roleId = (Integer)ServletActionContext.getRequest().getSession().getAttribute(Constants.USERSESSIONROLEID);
        pv = permissionService.findPermissionVO(roleId);
        url = "html/apply-bw.jsp";
        return SUCCESS;
    }
    
    public String createJournal() {
        int roleId = (Integer)ServletActionContext.getRequest().getSession().getAttribute(Constants.USERSESSIONROLEID);
        pv = permissionService.findPermissionVO(roleId);
        url = "html/createJournal.jsp";
        return SUCCESS;
    }
    
    public String submit_article() {
        int roleId = (Integer)ServletActionContext.getRequest().getSession().getAttribute(Constants.USERSESSIONROLEID);
        pv = permissionService.findPermissionVO(roleId);
        url = "space/article.jsp";
        return SUCCESS;
    }
    
    public CategoryService getCs() {
        return cs;
    }
    @Resource(name="categoryService")
    public void setCs(CategoryService cs) {
        this.cs = cs;
    }

    public PerPeriodicalService getPps() {
        return pps;
    }
    @Resource(name="perPeriodicalService")
    public void setPps(PerPeriodicalService pps) {
        this.pps = pps;
    }

    public ArticalService getAs() {
        return as;
    }
    @Resource(name="articalService")
    public void setAs(ArticalService as) {
        this.as = as;
    }
    
    public AdsService getAdsService() {
        return adsService;
    }
    @Resource(name="adsService")
    public void setAdsService(AdsService adsService) {
        this.adsService = adsService;
    }

	public List<PerPeriodical> getPerPeriodicals_0() {
		return perPeriodicals_0;
	}

	public void setPerPeriodicals_0(List<PerPeriodical> perPeriodicals_0) {
		this.perPeriodicals_0 = perPeriodicals_0;
	}

	public List<Category> getCategorys() {
		return categorys;
	}

	public void setCategorys(List<Category> categorys) {
		this.categorys = categorys;
	}

	public List<PerPeriodical> getPerPeriodicals_1() {
		return perPeriodicals_1;
	}

	public void setPerPeriodicals_1(List<PerPeriodical> perPeriodicals_1) {
		this.perPeriodicals_1 = perPeriodicals_1;
	}

	public List<Artical> getArticals() {
		return articals;
	}

	public void setArticals(List<Artical> articals) {
		this.articals = articals;
	}

	public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }
    
    public List<PermissionVO> getPv() {
        return pv;
    }

    public void setPv(List<PermissionVO> pv) {
        this.pv = pv;
    }
    
    public PermissionService getPermissionService() {
        return permissionService;
    }
    @Resource(name="permissionService")
    public void setPermissionService(PermissionService permissionService) {
        this.permissionService = permissionService;
    }

	public Ads getAds_center() {
		return ads_center;
	}

	public void setAds_center(Ads ads_center) {
		this.ads_center = ads_center;
	}

	public Ads getAds_bottom() {
		return ads_bottom;
	}

	public void setAds_bottom(Ads ads_bottom) {
		this.ads_bottom = ads_bottom;
	}
}
